#lang racket
(define (flatten1 seq)
  (if (not (list? seq))
           (list seq)
           (apply append
             (map flatten seq))))
(flatten1 '((1 2) ((3) ((4) (5 (2 (1 3) 4)) 5)) 10))


(define (flatten2 seq)
  (cond ((null? seq) '())
        ((list? (car seq))
         (append (flatten2 (car seq))
                 (flatten2 (cdr seq))))
        (else (cons (car seq)
                    (flatten2 (cdr seq))))))
(flatten2 '((1 2) ((3) ((4) (5 (2 (1 3) 4)) 5)) 10))


(define (flatten3 seq)
  (cond ((null? seq) '())
        ((not (pair? seq)) (list seq))
        (else (append (flatten3 (car seq))
                      (flatten3 (cdr seq))))))
(flatten3 '((1 2) ((3) ((4) (5 (2 (1 3) 4)) 5)) 10))
  


        
